package user

import (
	"cloud_android_backend/api/common"
	"cloud_android_backend/pkg/middleware/authorization"
	model "cloud_android_backend/pkg/models/users"
	"cloud_android_backend/pkg/modules/users"
	"fmt"
	"github.com/gin-gonic/gin"
	rb "modules.tenxcloud.com/common/middleware"
	"net/http"
)

func Register(application *gin.RouterGroup) {

	application.GET("/user/profile", authorization.TokenCheck, GetUserProfile)
	application.POST("/test/test1", rb.RequestBody, Test1)
}

func GetUserProfile(c *gin.Context) {
	li, exists := c.Get(authorization.LoginUserKey)
	if !exists {
		c.AbortWithStatusJSON(common.ErrorResponse("get user from content failed"))
		return
	}
	current := li.(*model.User)
	userProfile, err := users.GetUserInfo(current.UserID)
	if err != nil {
		c.AbortWithStatusJSON(common.ErrorResponse(err.Error()))
		return
	}
	c.JSON(http.StatusOK, common.SuccessResponse(userProfile))
}

func Test1(c *gin.Context) {
	body, _ := c.Get(rb.RequestBodyKey)
	fmt.Println("test1body")
	fmt.Printf("test111111>>>>>>>>>>>body:%s", string(body.([]byte)))
	c.JSON(http.StatusOK, common.SuccessResponse("test1"))
}
